﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>会员充值</title>
<link href="../js/ui/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="../js/function.js" type="text/javascript"></script>
<script src="../js/base.js" type="text/javascript"></script>
<script src="../js/dialog.js" type="text/javascript"></script>
<script src="../js/jquery-form.js" type="text/javascript"></script>
<script src="../js/ajax-data.js" type="text/javascript"></script>
<script src="../js/Pager.js" type="text/javascript"></script>
<style>
body{ background-color: White;}
.form_table td{ height:26px;}
td input {width:300px;}
.list {border-collapse: collapse;border: none;width:640px; text-align:center;}
.list td{border: solid #ccc 1px;color:Black; height:26px;}
td a{ text-decoration:none;}
#rad1,#rad2{ width:initial;}
.form_table label{margin:0px;}
</style>
</head>
<body class="mainbody">
<div class="navigation"><a href="javascript:history.go(-1);" class="back">后退</a>首页 &gt; 代理商 &gt; 会员充值</div>
<div id="tab">
    <ul class="tab_nav">
        <li class="selected"><a href="javascript:;">基本信息</a></li>
    </ul>
    <div class="tab_con" style="display:block;">
        <table class="form_table">
            <col width="150px"><col>
            <tbody>
            <tr>
                <th>微街秀ID：</th>
                <td>
                    <input type="text" id="user_id" name="user_id" onblur="get()" />
                    <label>* 6位以上的数字。</label>
                </td>
            </tr>
            <tr>
                <th>用户名：</th>
                <td id="name">                    
                </td>
            </tr>
            <tr>
                <th>公司名：</th>
                <td id="sitename">                    
                </td>
            </tr>
           
            <tr>
                <th>余额：</th>
                <td id="balance" style="color:Red; font-weight:bold;">
                </td>
            </tr>               
            <tr>
                <th>充值金额：</th>
                <td>
                    <input type="text" id="amount" name="amount" maxlength="8" value="0" />
                     <label>* 可以为负数，需在备注中说明。</label>
                </td>
            </tr>
            <tr>
                <th>类型：</th>
                <td style="">                    
                <div style="width:500px; text-align:left;">
                    <input type="radio" id="rad1" name="direction" value="1"  onclick="Set(1)"/><label for="rad1">收入</label>
                    <input type="radio" id="rad2" name="direction" value="2" onclick="Set(2)" /><label for="rad2">支出</label>
                    </div>
                </td>
            </tr>      
            <tr>
                <th>备 注：</th>
                <td>
                   <textarea id="remarks" name="remarks" style="height:60px; width:500px;">管理员充值</textarea>
                   <br /><label>* 备注内容代理商也能看见。</label>
                </td>
            </tr>
            </tbody>
        </table>

    </div>
    <div class="foot_btn_box" style=" text-align:left; padding-left:150px;">
        <input type="button" value="提 交" onclick="submits()" style="width:100px;"/>
    </div>
     <table class="list">
            <tr class="th">
                <td>日期</td>
                <td>单笔金额</td>
                <td>余额</td>
                <td>类型</td>
                <td>广告</td>
                <td>备注</td>
            </tr>
            <tbody id="list"></tbody>
        </table>
</div>
<script>
    $(function () {
        var user_id = getUrlArgStr("user_id");
        if (user_id != "") {
            $("#user_id").val(user_id);
            $("#user_id").blur();
        }

    })
    function Set(tab) {
        if (tab == 1) {
            if ($("#remarks").html() == "" || $("#remarks").html() == "管理员扣费")
                $("#remarks").html("管理员充值")
        }
        if (tab == 2) {
            if ($("#remarks").html() == "" || $("#remarks").html() == "管理员充值")
                $("#remarks").html("管理员扣费")
        }
    }

    function submits() {
        var s = '';
        var param = { "user_id": $("#user_id").val(), "name": $("#name").text(), "amount": $("#amount").val(), "remarks": $("#remarks").val(), "direction": 0, "adminid": adminid, "token": token };
        if (param.user_id == "") {
            Alert("请填写微街秀ID")
            return false;
        }
        if (param.amount == "") {
            Alert("请输入金额")
            return false;
        }
        if (isNaN(param.amount)) {
            Alert("数字必须是数字")
            return false;
        }
        if (parseInt(param.amount) > 50000) {
            Alert("金额不能超过￥ 50000 元,可以分多次充值")
            return false;
        }

        if (document.getElementById("rad1").checked) {
            if (param.amount < 0)
                param.amount = param.amount * -1;
            param.direction = 1;
            s = '收入';
        } else if (document.getElementById("rad2").checked) {
            if (param.amount > 0)
                param.amount = param.amount * -1;
            param.direction = 2;
            s = '支出';
        } else {
            Alert("请选择类型");
            return false;
        }

        if (param.remark == "") {
            Alert("请填写备注")
            return false;
        }
        var msg = "微街秀ID：" + param.user_id + "\n" + "类型：" + s + "\n" + "金额：" + param.amount + "元\n确认要提交吗？";
        if (!confirm(msg))
            return;

        $.post("../ajax/user.ashx?setmoney", param, function (data) {
            if (data.code == 0) {
                var balance = $("#balance").html();
                if (balance != "")
                    $("#balance").html(parseFloat(balance) + parseFloat(param.amount))
                Alert("操作成功");
                GetList(1);
            }
            else
                Alert(data.msg);
        }, "json");
    }

    var oldId = "";
    function get() {
        var obj = document.getElementById("user_id");
        if (obj.value == "") return;
        if (oldId == obj.value) return;
        $("#name").html("");
        $("#list").html("");
        $("#sitename").html("");
        $("#balance").html("");
        $.get("../ajax/user.ashx?GetDetail", { "user_id": obj.value }, function (data) {
            oldId = obj.value;
            if (data.code != 0)
                Alert(data.msg);
            else {
                if (data.item == null) {
                    Alert("会员不存在")
                    return;
                }
                $("#name").html(data.item.name);
                $("#sitename").html(data.item.nick_name);
                $("#balance").html(data.item.ad_balance);

                GetList(1);
            }
        }, "json");
    }

    //获取代理商的金额消费记录
    function GetList(page) {
        var param = "page_index=" + page + "&rand=" + Math.random();
        param += "&userid=" + $("#user_id").val();

        $("#list").html("");
        var html = "";
        AjaxStart("../ajax/fc_record.ashx?getlist", param, function (data) {
            if (data.code != 0) {
                $("#list").html(html + "<tr><td colspan='8'>" + data.msg + "</td></tr>");
            }
            else {
                $("#list").html("");
                var list = data.item.table;
                for (var i = 0; i < list.length; i++) {
                    var direction = "";
                    if (list[i].direction == 1)
                        direction = "收入";
                    else if (list[i].direction == 2)
                        direction = "支出";
                    var state = '';
                    if (list[i].state == 1)
                        state = "<span style='color: green;'>成功</span>";
                    else if (list[i].state == 0) {
                        if (list[i].callback_date == null)
                            state = "<span style='color:#ccc;'>取消</span>";
                        else
                            state = "<span style='color:red'>失败</span>";
                    }
                    html += "<tr>";
                    html += "<td>" + DateFormat(list[i].date) + "</td>";
                    html += "<td>" + (list[i].direction == 1 ? "+" + list[i].amount : list[i].amount) + "元</td>";
                    html += "<td>" + list[i].balance + "元</td>";
                    html += "<td>" + direction + "</td>";
                    
                    html += "<td>" + "<a href='../../client/fc_detail.aspx?article_id=" + list[i].articleid + "' target=\"_blank\">" + (list[i].title == null ? "" : list[i].title) + "</a></td>";
                    var remark = "";
                    if (list[i].direction == 1)
                        remark = (list[i].remark == null ? "" : list[i].remark);
                    else
                        remark = (list[i].remark == null ? "提现" : list[i].remark);
                    html += "<td style='text-align:left;'>" + remark + "</td>";
                    html += "</tr>";
                }

                $("#list").html(html);
                var pager = new Pager();
                $(".page_info").css("display", "block")
                pager.initPage(page, data.item.itemCount, 20, 5, GetList);
            }
        });
    }
    function DateFormat(date) {
        return date.toString().replace("T", " ").substring(0, 19)
    }
</script>
</body>
</html>
